﻿using AnesSystem.Services;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// 麻醉单头部基本信息
    /// </summary>
    public partial class AnesRecordBaseInfoCtrl : UserControl
    {
        public AnesRecordBaseInfoCtrl()
        {
            InitializeComponent();

            this.Loaded += AnesRecordBaseInfoCtrl_Loaded;

            asa1_ValuegetAnescored();
            nnis0_ValueGetAneth();
            FenJiCtrl_PropertyGetAneth();
            xingGongNeng_ValuegetAnescored();
            InteZqJz();
            InitRadioButton();
        }

        private void InitRadioButton()
        {
            new RadioButtonHelper().ChangeRadioSatus(zq, jz);
            new RadioButtonHelper().ChangeRadioSatus(jss, jsf);
            new RadioButtonHelper().ChangeRadioSatus(fjhss, fjhssf);
            new RadioButtonHelper().ChangeRadioSatus(flg, flz, fld);
            new RadioButtonHelper().ChangeRadioSatus(ponvg, ponvz, ponvd);
        }

        private void AnesRecordBaseInfoCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            DateTime ssrqda = DataManager.Instance.CurrentPatientLink.Status.InRoomTime;
            string date = Convert.ToDateTime(ssrqda).ToString("yyyy-MM-dd");
            ssrq.Text = date;


        }



        private void InteZqJz()
        {
            bool zqtrue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Zq;
            bool jztrue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Jz;
            bool jstrue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Js;
            bool bjstrue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Bis;
            if (!jstrue && !bjstrue)
            {
                if (zqtrue)
                {
                    DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Js = true;
                    DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Jhss = true;
                }
                else if (jztrue)
                {
                    DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Bjs = true;
                    DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Fjhss = true;

                }
            }

        }




        private void BindTextCtrl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            AnesMethodsWin anesMethodsCtrl = new AnesMethodsWin();
            DrugAndEventWindow.Instance.Content = anesMethodsCtrl;
            DrugAndEventWindow.Instance.ShowDialog();
        }
        private void setZhiKonXin()
        {

        }
        private void BindTextCtrl_Loaded(object sender, RoutedEventArgs e)
        {

        }


        private void nnis0_ValueGetAneth()
        {
            List<string> nisList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "NanTongShuQianFangShi", "nnis1", "nnis2", "nnis3", "nnis4");
            string nisValue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nnis;
            if (string.IsNullOrEmpty(nisValue))
            {
                for (int i = 0; i < nisList.Count; i++)
                {
                    if (nisList[i].Equals("True"))
                    {
                        DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nnis = i.ToString();

                    }

                }
                return;
            }

        }
        private void FenJiCtrl_PropertyGetAneth()
        {
            List<string> knList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "NanTongShuQianFangShi", "fj");
            string knqdValue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Knqd;
            if (string.IsNullOrEmpty(knqdValue) && knList.Count != 0)
            {
                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Knqd = knList[0];
            }

        }


        private void asa1_ValuegetAnescored()
        {
            List<string> arList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "NanTongShuQianFangShi", "asa1", "asa2", "asa3", "asa4", "asa5", "asa6");
            string asaValue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level;
            if (string.IsNullOrEmpty(asaValue))
            {
                for (int i = 0; i < arList.Count; i++)
                {
                    if (arList[i].Equals("True"))
                    {
                        switch (i)
                        {
                            case 0:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅰ";
                                break;
                            case 1:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅱ";
                                break;
                            case 2:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅲ";
                                break;
                            case 3:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅳ";
                                break;
                            case 4:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅴ";
                                break;
                            case 5:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Asa.Level = "Ⅵ";
                                break;

                        }

                    }
                }
                return;
            }
        }
          private void xingGongNeng_ValuegetAnescored()
        {
            List<string> arList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "NanTongShuQianFangShi", "xgn1", "xgn2", "xgn3", "xgn4");
            string asaValue = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nyha;
            if (string.IsNullOrEmpty(asaValue))
            {
                for (int i = 0; i < arList.Count; i++)
                {
                    if (arList[i].Equals("True"))
                    {
                        switch (i)
                        {
                            case 0:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nyha= "Ⅰ";
                                break;
                            case 1:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nyha= "Ⅱ";
                                break;
                            case 2:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nyha= "Ⅲ";
                                break;
                            case 3:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.Nyha= "Ⅳ";
                                break;
                            

                        }

                    }
                }
                return;
            }
        }


    }

}
